// Konfirmasi saat hapus data
var elems = document.getElementsByClassName('hapus');
var confirmIt = function (e) {
	if (!confirm('Yakin mau dihapus?')) e.preventDefault();
};
for (var i = 0, l = elems.length; i < l; i++) {
	elems[i].addEventListener('click', confirmIt, false);
}

// Tagslist
var boleh = '/profil'
if(boleh != window.location.pathname){
		async function getTags() {
			let url = "/tagslist";
			try {
				let response = await fetch(url);
				return await response.json();
			} catch (err) {
				console.log(err);
			}
		}

		async function tlist() {
			let data = await getTags();
			let html = '';

			for (f in data) {
				html += `<h5 class='sembunyi'> ${data[f].abjad} </h5>`;
				for(u in data[f].tags) {
					let list = `
						<span><a href="/tags/${data[f].tags[u]}">${data[f].tags[u]}</a></span>
					`;
				
				html += list
			}}

			let el = document.querySelector('.tagslist');
			el.innerHTML = html;
		}
		tlist()
}

var profil = '/profil';
if (profil == window.location.pathname) {
	var hidden = document.getElementById("gantiPwd").onclick = function (){
		var el = document.getElementById("gp");
		if(el.style.display === "none") {
			el.style.display = "block";
		}else{
			el.style.display = "block"
		}
}}
